package com.example.takeaway.websocket.message;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 邢晨旭
 * {@code @date} 2023/10/26
 */
@Getter
@AllArgsConstructor
public enum MessageType {
    /**
     * 订单创建消息
     */
    ORDER_NEW(1),
    /**
     * 通知消息
     */
    NOTICE(2),
    /**
     * 系统消息
     */
    SYSTEM(3),
    /**
     * 关闭消息
     */
    CLOSE(4),
    ;

    private final Integer type;

    private static final Map<Integer, MessageType> MESSAGE_TYPES = new HashMap<>(MessageType.values().length);

    static {
        for (MessageType messageType : MessageType.values()) {
            MESSAGE_TYPES.put(messageType.getType(), messageType);
        }
    }

    public static boolean isMessageType(Integer type) {
        return MESSAGE_TYPES.containsKey(type);
    }

    public static MessageType get(Integer type) {
        return MESSAGE_TYPES.get(type);
    }
}
